// pages/component/homes/earningdetail/earningdetail.js
var that;
var dataManager = require('../../../../utils/dataManager.js');
var GlobalData = require('../../../../utils/GlobalData.js');
var Util = require('../../../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    earningArr: [],
    page: 20,
    arrlength: 0,
    haveData: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
     dataManager.removeBtnObserver("earningdetail")
    if (GlobalData.EarningDetail) {
      this.onComplete();
    } else {
      dataManager.rigisterObserver("earningdetail", this.onComplete, this);
      dataManager.getEarningDetail(GlobalData.EarningDetailother["index"], GlobalData.EarningDetailother["size"], GlobalData.EarningDetailother["add"]);
    }


  },
  onComplete: function () {
    if (GlobalData.EarningDetail.length == this.data.arrlength)
      return;
    if (GlobalData.EarningDetail)
      var arrTemp = GlobalData.clone(GlobalData.EarningDetail);
    for (let i = 0; i < arrTemp.length; i++) {
      let moeny = parseInt(arrTemp[i].moeny);
      let str = "" + arrTemp[i].moeny;
      if (moeny > 0 && str.indexOf("+") < 0)
        arrTemp[i].moeny = "+" + arrTemp[i].moeny;
      arrTemp[i].createtime = arrTemp[i].createtime.replace('T', ' ');
      if (arrTemp[i].type == "1" || arrTemp[i].type == "0")
        arrTemp[i].type = arrTemp[i].type == "1" ? "收益:" : "提现:";

      if (arrTemp[i].state == "1" || arrTemp[i].state == "0")
        arrTemp[i].state = arrTemp[i].state == "1" ? "完成" : "未处理";
    }
    /**
     *  moeny 
        createtime
        state
        type  这四个字段 type 0 为提现 1.收益  state 0未处理 1.完成
     */
    this.setData({
      earningArr: arrTemp
    })
    this.arrlength = this.data.earningArr.length;
    /**判断是否有数据 */
    if (this.data.earningArr.length == 0)
      this.haveData = true;

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    GlobalData.EarningDetailother["index"] = GlobalData.EarningDetailother["index"] + 1;
    dataManager.rigisterObserver("EarningDetail", this.onComplete, this);
    dataManager.getEarningDetail(GlobalData.EarningDetailother["index"], GlobalData.EarningDetailother["size"], true);

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})